<template>
  <div class="container">
    <a-row class="carousel-wrap" :gutter="[40]">
      <a-col :span="15" :xs="0" :md="0" :lg="15">
        <div class="left-box">
          <NuxtLink
            :to="`/movie/${pageState.banner[0]?.moviesId}`"
            class="image_imageItem"
          >
            <img
              :alt="pageState.banner[0]?.movies.name"
              loading="lazy"
              :src="pageState.banner[0]?.movies.cover"
            />
          </NuxtLink>
          <a-flex class="card-content" vertical justify="space-between">
            <div class="content-top">
              <NuxtLink
                class="title"
                :to="`/movie/${pageState.banner[0]?.moviesId}`"
                >{{ pageState.banner[0]?.movies.name }}</NuxtLink
              >
              <NuxtLink
                class="chapter-count"
                :to="`/movie/${pageState.banner[0]?.moviesId}`"
                >100 集</NuxtLink
              >
              <NuxtLink
                class="intro"
                :to="`/movie/${pageState.banner[0]?.moviesId}`"
              >
                {{ pageState.banner[0]?.movies.introduction }}
              </NuxtLink>
            </div>
            <div class="tag-box">
              <NuxtLink
                class="tag-item"
                :to="`/movie/${pageState.banner[0]?.moviesId}`"
                v-for="(category, index) in pageState.banner[0]?.movies
                  ?.category"
                :key="index"
                >{{ category }}</NuxtLink
              >
            </div>
          </a-flex>
        </div>
      </a-col>
      <a-col :span="9" :xs="0" :md="0" :lg="9">
        <div class="right-box">
          <div class="box1">
            <NuxtLink
              :to="`/movie/${pageState.banner[1]?.moviesId}`"
              class="image_imageItem"
            >
              <img
                :alt="pageState.banner[1]?.movies.name"
                loading="lazy"
                :src="pageState.banner[1]?.movies.cover"
              />
            </NuxtLink>
            <a-flex class="card-content" vertical justify="space-between">
              <div class="content-top">
                <NuxtLink
                  class="title"
                  :to="`/movie/${pageState.banner[1]?.moviesId}`"
                >
                  {{ pageState.banner[1]?.movies.name }}
                </NuxtLink>
                <NuxtLink
                  class="chapter-count"
                  :to="`/movie/${pageState.banner[1]?.moviesId}`"
                  >100 集</NuxtLink
                >
                <NuxtLink
                  class="intro"
                  :to="`/movie/${pageState.banner[1]?.moviesId}`"
                >
                  {{ pageState.banner[1]?.movies.introduction }}</NuxtLink
                >
              </div>
              <div class="tag-box">
                <NuxtLink
                  class="tag-item"
                  :to="`/movie/${pageState.banner[1]?.moviesId}`"
                  v-for="(category, index) in pageState.banner[1]?.movies
                    ?.category"
                  :key="index"
                  >{{ category }}</NuxtLink
                >
              </div>
            </a-flex>
          </div>
          <div class="box2">
            <NuxtLink
              :to="`/movie/${pageState.banner[2]?.moviesId}`"
              class="image_imageItem"
            >
              <img
                :alt="pageState.banner[2]?.movies.name"
                loading="lazy"
                :src="pageState.banner[2]?.movies.cover"
              />
            </NuxtLink>
            <a-flex class="card-content" vertical justify="space-between">
              <div class="content-top">
                <NuxtLink
                  class="title"
                  :to="`/movie/${pageState.banner[2]?.moviesId}`"
                >
                  {{ pageState.banner[2]?.movies.name }}
                </NuxtLink>
                <NuxtLink
                  class="chapter-count"
                  :to="`/movie/${pageState.banner[2]?.moviesId}`"
                  >100 集</NuxtLink
                >
                <NuxtLink
                  class="intro"
                  :to="`/movie/${pageState.banner[2]?.moviesId}`"
                >
                  {{ pageState.banner[2]?.movies.introduction }}
                </NuxtLink>
              </div>
              <div class="tag-box">
                <NuxtLink
                  class="tag-item"
                  :to="`/movie/${pageState.banner[2]?.moviesId}`"
                  v-for="(category, index) in pageState.banner[2]?.movies
                    ?.category"
                  :key="index"
                  >{{ category }}</NuxtLink
                >
              </div>
            </a-flex>
          </div>
        </div>
      </a-col>
      <!-- h5端 -->
      <a-col :span="24" :md="24" :lg="0" style="height: 100%">
        <a-carousel>
          <div v-for="(item, index) in 3" :key="index">
            <div class="left-box">
              <NuxtLink to="/movie/1" class="image_imageItem">
                <img
                  alt="闪婚老公是豪门"
                  loading="lazy"
                  src="https://sres.dramaboxdb.com/data/cppartner/4x1/41x0/410x0/41000100525/41000100525.jpg@w=240&amp;h=320"
                />
              </NuxtLink>
              <a-flex class="card-content" vertical justify="space-between">
                <div class="content-top">
                  <NuxtLink class="title" to="/movie/1"
                    >闪婚老公是豪门</NuxtLink
                  >
                  <NuxtLink class="chapter-count" to="/movie/1"
                    >100 集</NuxtLink
                  >
                  <NuxtLink class="intro" to="/movie/1"
                    >司情在入职战氏集团当天，被奶奶包办婚姻，与第一次见面的男人杭江领了证后，杭江就消失了。一年后，战氏总裁战北霆从美国回来，司情总觉得人眼熟，却想不清楚在哪儿见过。与此同时，消失了一年的便宜老公杭江也突然冒了出来提离婚，却因为种种意外没能成功。</NuxtLink
                  >
                </div>
                <div class="tag-box">
                  <NuxtLink class="tag-item" to="/movie/1">现代言情</NuxtLink>
                </div>
              </a-flex>
            </div>
          </div>
        </a-carousel>
      </a-col>
    </a-row>
    <a-flex class="title-wrap" justify="space-between">
      <h2>必看好剧</h2>
      <NuxtLink to="/movie/1" class="more"> 更多 <RightOutlined /></NuxtLink>
    </a-flex>
    <a-row class="episode-list" :gutter="16">
      <a-col
        :span="4"
        :xs="8"
        :md="8"
        :lg="4"
        v-for="(item, index) in pageState.mustWatch"
        :key="item.id"
      >
        <div class="book-item">
          <NuxtLink :to="`/movie/${item.id}`" class="book-image">
            <img :alt="item.name" loading="lazy" :src="item.cover" />
          </NuxtLink>
          <div class="chapter-count">{{ item.episodeCount }} 集</div>
          <div class="book-name">{{ item.name }}</div>
          <div class="book-name-box">
            <div class="book-name-hover">{{ item.name }}</div>
            <div class="tag-box">
              <NuxtLink
                class="tag-item"
                :to="`/movie/${item.id}`"
                v-for="(category, index) in item?.category"
                :key="index"
              >
                {{ category }}
              </NuxtLink>
            </div>
          </div>
        </div>
      </a-col>
    </a-row>
    <a-flex class="title-wrap" justify="space-between">
      <h2>当前热播</h2>
      <NuxtLink to="/movie/1" class="more"> 更多 <RightOutlined /></NuxtLink>
    </a-flex>
    <a-row class="episode-list" :gutter="16">
      <a-col
        :span="4"
        :xs="8"
        :md="8"
        :lg="4"
        v-for="(item, index) in pageState.currentlyAiring"
        :key="item.id"
      >
        <div class="book-item">
          <NuxtLink to="/movie/1" class="book-image">
            <img :alt="item.name" loading="lazy" :src="item.cover" />
          </NuxtLink>
          <div class="chapter-count">{{ item.episodeCount }} 集</div>
          <div class="book-name">{{ item.name }}</div>
          <div class="book-name-box">
            <div class="book-name-hover">{{ item.name }}</div>
            <div class="tag-box">
              <NuxtLink
                class="tag-item"
                :to="`/movie/${item.id}`"
                v-for="(category, index) in item?.category"
                :key="index"
              >
                {{ category }}
              </NuxtLink>
            </div>
          </div>
        </div>
      </a-col>
    </a-row>
    <a-flex class="title-wrap" justify="space-between">
      <h2>精彩剧集</h2>
      <NuxtLink to="/movie/1" class="more"> 更多 <RightOutlined /></NuxtLink>
    </a-flex>
    <a-row class="episode-list" :gutter="16">
      <a-col
        :span="4"
        :xs="8"
        :md="8"
        :lg="4"
        v-for="(item, index) in pageState.featured"
        :key="item.id"
      >
        <div class="book-item">
          <NuxtLink to="/movie/1" class="book-image">
            <img :alt="item.name" loading="lazy" :src="item.cover" />
          </NuxtLink>
          <div class="chapter-count">{{ item.episodeCount }} 集</div>
          <div class="book-name">{{ item.name }}</div>
          <div class="book-name-box">
            <div class="book-name-hover">{{ item.name }}</div>
            <div class="tag-box">
              <NuxtLink
                class="tag-item"
                :to="`/movie/${item.id}`"
                v-for="(category, index) in item?.category"
                :key="index"
              >
                {{ category }}
              </NuxtLink>
            </div>
          </div>
        </div>
      </a-col>
    </a-row>
  </div>
</template>
<script setup lang="ts">
import { RightOutlined } from "@ant-design/icons-vue"
import { request as getMoviePageRequest } from "~/api/server/mods/movie/getHomeMovie"
import { request as getBannerListRequest } from "~/api/server/mods/banner/getBannerList"
import { errorTips } from "@/utils"
interface MovieEntity extends defs.server.MovieEntity {
  episodeCount?: number
}
const pageState = reactive({
  banner: [] as defs.server.BannerEntity[],
  /** 正在热映 */
  currentlyAiring: [] as MovieEntity[],
  /** 精彩剧集 */
  featured: [] as MovieEntity[],
  /** 必看剧 */
  mustWatch: [] as MovieEntity[],
})
getHomeData()
async function getHomeData() {
  try {
    const { data, success } = await getMoviePageRequest({})
    if (success) {
      pageState.currentlyAiring = data?.currentlyAiring ?? []
      pageState.featured = data?.featured ?? []
      pageState.mustWatch = data?.mustWatch ?? []
    }
  } catch (error: any) {
    errorTips(error.message)
  }
}
getBanner()
async function getBanner() {
  try {
    const { data, success } = await getBannerListRequest({})
    if (success) {
      pageState.banner = data ?? []
    }
  } catch (error: any) {
    errorTips(error.message)
  }
}
</script>
<style lang="scss" scoped>
.container {
  .carousel-wrap {
    height: 4.6rem;
    margin: 16px 0 40px;
    .ant-col {
      height: 100%;
    }
    .left-box,
    .box1,
    .box2 {
      &:hover .title {
        color: #ff375f !important;
        transition: color 0.3s;
      }
    }
    .left-box {
      height: 100%;
      background-color: rgba(50, 50, 57, 0.07);
      border-radius: 0.04rem;
      overflow: hidden;
      display: flex;
    }
    .right-box {
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      grid-gap: 0.2rem;
      .box1,
      .box2 {
        border-radius: 0.04rem;
        height: 50%;
        display: flex;
        overflow: hidden;
      }
      .box1 {
        background-color: rgba(50, 50, 57, 0.07);
      }
      .box2 {
        background-color: rgba(50, 50, 57, 0.07);
      }
      .image_imageItem {
        width: 1.65rem;
        height: 100%;
      }
      .card-content {
        .content-top {
          .intro {
            font-size: 0.14rem;
            -webkit-line-clamp: 2;
          }
        }
      }
    }
    .image_imageItem {
      width: 3.45rem;
      height: 100%;
      overflow: hidden;
      display: block;
      &:hover {
        img {
          transform: scale(1.1);
        }
      }
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        transition: all 0.5s;
      }
    }
    .card-content {
      flex: 1 1;
      padding: 0.2rem 0.2rem 0.28rem;
      height: 100%;
      .content-top {
        box-sizing: border-box;
        .title {
          font-size: 0.24rem;
          font-weight: 500;
          color: rgba(0, 0, 0, 0.9);
          line-height: 0.32rem;
          margin-bottom: 0.2rem;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          word-wrap: break-word;
          overflow: hidden;
          text-decoration: none;
        }
        .chapter-count {
          display: inline-block;
          font-size: 0.14rem;
          font-weight: 400;
          color: rgba(0, 0, 0, 0.9);
          line-height: 0.2rem;
          margin-bottom: 0.2rem;
        }
        .intro {
          font-size: 0.14rem;
          font-weight: 400;
          color: rgba(0, 0, 0, 0.6);
          line-height: 0.2rem;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 10;
          word-wrap: break-word;
          overflow: hidden;
        }
      }
      .tag-box {
        font-size: 0.12rem;
        font-weight: 400;
        gap: 0.08rem;
        display: flex;
        flex-wrap: wrap;
        height: 0.24rem;
        overflow: hidden;
        .tag-item {
          color: rgba(0, 0, 0, 0.6);
          border-radius: 1rem;
          padding: 0 0.1rem;
          background-color: rgba(50, 50, 57, 0.07);
          height: 0.24rem;
          line-height: 0.24rem;
          max-width: 3rem;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          transition: color 0.3s;
        }
      }
    }
  }
  :deep(.slick-dots) {
    button {
      background-color: rgba(0, 0, 0, 0.5) !important;
    }
    .slick-active {
      button {
        background-color: #ff375f !important;
      }
    }
  }
}
@media (max-width: 768px) {
  .container {
    .carousel-wrap {
      height: 2.94rem;
      .image_imageItem {
        width: 2.18rem !important;
      }
      .title {
        font-size: 0.28rem !important;
      }
      .chapter-count {
        font-size: 0.22rem !important;
      }
      .intro {
        font-size: 0.24rem !important;
        font-weight: 400 !important;
        color: rgba(0, 0, 0, 0.4) !important;
        line-height: 0.33rem !important;
        -webkit-line-clamp: 2 !important;
      }
      .card-content {
        height: auto !important;
        .tag-box {
          height: 0.36rem !important;
          .tag-item {
            font-size: 0.22rem !important;
            padding: 0 0.12rem !important;
            line-height: 0.36rem !important;
            height: 0.36rem !important;
          }
        }
      }
    }
  }
}
</style>
